const Index = {
	getBase64: file => {
		return new Promise((resolve, reject) => {
			const reader = new FileReader()
			reader.readAsDataURL(file)
			reader.onload = () => resolve(reader.result)
			reader.onerror = error => reject(error)
		})
	},
	getType:  f => ({
		img: { bool:  f === 'image/png' || f === 'image/jpg' || f === 'image/jpeg' || f === 'image/gif' , msg: '图片文件' },
		pdf: { bool: f === 'application/pdf', msg:'PDF 文件'},
		video: { bool: ['video/mp4', 'video/avi'].includes(f), msg:'视频文件'},
		doc: { bool: f === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', msg:'word 文件'},
		xls: { bool: f === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || f ==='application/vnd.ms-excel', msg:'Excel 文件'}
	}),
	isImage: url => /\.(gif|jpg|jpeg|png|GIF|JPEG|JPG|PNG)$/.test(url),
	getFileList: (value, file) => {
		const { $fn } = window 
		if(Array.isArray( value )){
			return value.map( v => {
				if($fn.isString(v)){
					return { uid: v, name: v, status: 'done', url: $fn.url(v) }
				}else if( $fn.isObject(v) ){
					return { uid: v.id || v.url, name: v?.name || v.url, status: 'done', url: $fn.url(v.url) }
				}else{
					return { uid: 1, name: '上传失败', status: 'erro', url: null }
				}
			})
		}else if( $fn.isObject(value) ){
			return [{ uid: value.id || value.url , status: 'done', url:$fn.url(value.url), name: value?.name || file?.name }]
		}else if( $fn.isString(value) ){
			return [{ uid: value , status: 'done', url:$fn.url(value), name: file?.name || value }]
		}else{
			return []
		}
	},
}
export default Index